version 13
#delimit;
clear all;
set more off;
capture log close;


global strformat "%8.3f";

capture program drop sig_p;
program sig_p;
   args obj_var point_est_var point_sd_var p_val row_id_var row_num;
   local point_est `point_est_var';
   local point_sd `point_sd_var';
   if `p_val' > 0.1 {;
      replace `obj_var' = string(`point_est', "$strformat") if `row_id_var' == `row_num';
      };
   if `p_val' > 0.05 & `p_val' <= 0.1  {;
      replace `obj_var' = string(`point_est', "$strformat")+"*" if `row_id_var' == `row_num';
      };
   if `p_val' > 0.01 & `p_val' <= 0.05  {;
      replace `obj_var' = string(`point_est', "$strformat")+"**" if `row_id_var' == `row_num';
      };
   if `p_val' <= 0.01 {;
      replace `obj_var' = string(`point_est', "$strformat")+"***" if `row_id_var' == `row_num';
      };
   replace `obj_var' = "<" + string(`point_sd', "$strformat") + ">" + " " if `row_id_var' == `row_num' + 1;
   end;


*enter directory name here;

use "$dir/ReStat_children.dta", clear;


global fu_child_controls_cm
	"control_fu_child_age control_fu_female
	missing_fu_child_age missing_fu_female";
		
global fu_hh_controls_cm
	"control_fu_adults control_fu_hh_head_edu control_fu_hh_head_occ_farmer 
	control_fu_total_land control_fu_household_size
	missing_fu_adults missing_fu_hh_head_edu missing_fu_hh_head_occ_farmer 
	missing_fu_total_land missing_fu_household_size";



generate row_num = _n;




forvalues i=0/25 {;
	generate col`i' = "";
};


local row = 4;
sort row_num;
order col0-col25;



xi: regress fu_child_enrolled 
	treatment_1 treat_1_female 
	treatment_2 treat_2_female 
	$fu_hh_controls_cm $fu_child_controls_cm i.bl_district 
	if fu_child_level == 1 & fu_young_child == 1 [pw=hh_weight], cluster(villcode);
test treatment_1;
sig_p col3 _b[treatment_1] _se[treatment_1] r(p) row_num `row';
local row = `row' + 3;
test treat_1_female;
sig_p col3 _b[treat_1_female] _se[treat_1_female] r(p) row_num `row';
local row = `row' + 3;
test treatment_2;
sig_p col3 _b[treatment_2] _se[treatment_2] r(p) row_num `row';
local row = `row' + 3;
test treat_2_female;
sig_p col3 _b[treat_2_female] _se[treat_2_female] r(p) row_num `row';
local row = `row' + 3;
test control_fu_female ;
sig_p col3 _b[control_fu_female] _se[control_fu_female] r(p) row_num `row';
local row = `row' + 3;
replace col3 = string(e(N)) if row_num == `row';
local row = `row' + 1;
replace col3 = string(e(r2), "$strformat") if row_num == `row';
local row = `row' + 2;
test treatment_1 = treatment_2;
replace col3 = string(r(F), "$strformat") if row_num == `row';
local row = `row' + 1;
replace col3 = string(r(p), "$strformat") if row_num == `row';
local row = `row' + 2;
test treat_1_female = treat_2_female;
replace col3 = string(r(F), "$strformat") if row_num == `row';
local row = `row' + 1;
replace col3 = string(r(p), "$strformat") if row_num == `row';
local row = `row' + 2;
test treat_1_female + treat_2_female = 0;
replace col3 = string(r(F), "$strformat") if row_num == `row';
local row = `row' + 1;
replace col3 = string(r(p), "$strformat") if row_num == `row';
local row = `row' + 2;
test treatment_1 + treat_1_female = treatment_2 + treat_2_female;
replace col3 = string(r(F), "$strformat") if row_num == `row';
local row = `row' + 1;
replace col3 = string(r(p), "$strformat") if row_num == `row';

local row = 4;


xi: regress fu_child_highest_grade 
	treatment_1 treat_1_female 
	treatment_2 treat_2_female 
	$fu_hh_controls_cm $fu_child_controls_cm i.bl_district 
	if fu_child_level == 1 & fu_young_child == 1 [pw=hh_weight], cluster(villcode);
test treatment_1;
sig_p col5 _b[treatment_1] _se[treatment_1] r(p) row_num `row';
local row = `row' + 3;
test treat_1_female;
sig_p col5 _b[treat_1_female] _se[treat_1_female] r(p) row_num `row';
local row = `row' + 3;
test treatment_2;
sig_p col5 _b[treatment_2] _se[treatment_2] r(p) row_num `row';
local row = `row' + 3;
test treat_2_female;
sig_p col5 _b[treat_2_female] _se[treat_2_female] r(p) row_num `row';
local row = `row' + 3;
test control_fu_female ;
sig_p col5 _b[control_fu_female] _se[control_fu_female] r(p) row_num `row';
local row = `row' + 3;
replace col5 = string(e(N)) if row_num == `row';
local row = `row' + 1;
replace col5 = string(e(r2), "$strformat") if row_num == `row';
local row = `row' + 2;
test treatment_1 = treatment_2;
replace col5 = string(r(F), "$strformat") if row_num == `row';
local row = `row' + 1;
replace col5 = string(r(p), "$strformat") if row_num == `row';
local row = `row' + 2;
test treat_1_female = treat_2_female;
replace col5 = string(r(F), "$strformat") if row_num == `row';
local row = `row' + 1;
replace col5 = string(r(p), "$strformat") if row_num == `row';
local row = `row' + 2;
test treat_1_female + treat_2_female = 0;
replace col5 = string(r(F), "$strformat") if row_num == `row';
local row = `row' + 1;
replace col5 = string(r(p), "$strformat") if row_num == `row';
local row = `row' + 2;
test treatment_1 + treat_1_female = treatment_2 + treat_2_female;
replace col5 = string(r(F), "$strformat") if row_num == `row';
local row = `row' + 1;
replace col5 = string(r(p), "$strformat") if row_num == `row';

local row = 4;

xi: regress total_score_dev 
	treatment_1 treat_1_female 
	treatment_2 treat_2_female 
	$fu_hh_controls_cm $fu_child_controls_cm i.bl_district 
	if fu_child_level == 1 & fu_young_child == 1 [pw=hh_weight], cluster(villcode);
test treatment_1;
sig_p col7 _b[treatment_1] _se[treatment_1] r(p) row_num `row';
local row = `row' + 3;
test treat_1_female;
sig_p col7 _b[treat_1_female] _se[treat_1_female] r(p) row_num `row';
local row = `row' + 3;
test treatment_2;
sig_p col7 _b[treatment_2] _se[treatment_2] r(p) row_num `row';
local row = `row' + 3;
test treat_2_female;
sig_p col7 _b[treat_2_female] _se[treat_2_female] r(p) row_num `row';
local row = `row' + 3;
test control_fu_female ;
sig_p col7 _b[control_fu_female] _se[control_fu_female] r(p) row_num `row';
local row = `row' + 3;
replace col7 = string(e(N)) if row_num == `row';
local row = `row' + 1;
replace col7 = string(e(r2), "$strformat") if row_num == `row';
local row = `row' + 2;
test treatment_1 = treatment_2;
replace col7 = string(r(F), "$strformat") if row_num == `row';
local row = `row' + 1;
replace col7 = string(r(p), "$strformat") if row_num == `row';
local row = `row' + 2;
test treat_1_female = treat_2_female;
replace col7 = string(r(F), "$strformat") if row_num == `row';
local row = `row' + 1;
replace col7 = string(r(p), "$strformat") if row_num == `row';
local row = `row' + 2;
test treat_1_female + treat_2_female = 0;
replace col7 = string(r(F), "$strformat") if row_num == `row';
local row = `row' + 1;
replace col7 = string(r(p), "$strformat") if row_num == `row';
local row = `row' + 2;
test treatment_1 + treat_1_female = treatment_2 + treat_2_female;
replace col7 = string(r(F), "$strformat") if row_num == `row';
local row = `row' + 1;
replace col7 = string(r(p), "$strformat") if row_num == `row';


local row = `row' + 3;

outsheet col0-col7 using "$dir/Table 5 Disaggregated Treatment.csv" if row_num < `row',
	comma replace;
